// 用户 发出 请求
//  导入
import axios from '@/utils/index.js'
// import store from '@/store'

export const userInfo = (mobile, code) => axios({
  method: 'post',
  url: 'v1_0/authorizations',
  data: {
    mobile,
    code
  }
})
//  获取用户 手机验证码
export const userCode = (mobile) => axios({
  method: 'get',
  url: `/v1_0/sms/codes/${mobile}`
})
// 获取用户基本信息
export const userBaseInfo = () => axios({
  method: 'get',
  url: 'v1_0/user'
  // headers: {
  //   Authorization: `Bearer ${store.state.user.token}`
  // }
})
// 获取文章列表
export const userArticleList = () => axios({
  method: 'get',
  url: 'v1_0/user/channels'
})

// 关注 用户
export const followUser = (id) => axios({
  method: 'POST',
  url: '/v1_0/user/followings',
  data: {
    target: id
  }
})
// 取消 关注 用户
export const cancleFollow = (id) => axios({
  method: 'DELETE',
  url: `/v1_0/user/followings/${id}`
})
// 收藏 文章
export const collecArtcle = (target) => axios({
  method: 'post',
  url: '/v1_0/article/collections',
  data: {
    target
  }
})

// 取消 收藏 文章
export const cancleCollecArtcle = (target) => axios({
  method: 'DELETE',
  url: `/v1_0/article/collections/${target}`
})
// 文章 点赞
export const clickLike = (target) => axios({
  method: 'post',
  url: '/v1_0/article/likings',
  data: {
    target
  }
})
// 取消 点赞 文章
export const cancleClickLike = (target) => axios({
  method: 'DELETE',
  url: `/v1_0/article/likings/${target}`
})

// 获取 用户 评论
export const getComments = ({ type = 'a', source, offset = null, limit = 20 }) => axios({
  method: 'get',
  url: '/v1_0/comments',
  params: {
    type,
    source,
    offset,
    limit
  }
})

// 编辑 用户 资料 信息
export const editUserProfile = ({ name, photo, gender, birthday, intro }) => axios({
  method: 'patch',
  url: 'v1_0/user/profile',
  data: {
    name,
    photo,
    gender,
    birthday,
    intro
  }
})
// 获取 用户 资料 信息
export const getUserProfile = () => axios({
  method: 'get',
  url: '/v1_0/user/profile'
})
export const updateUserAvatar = data => {
  return axios({
    method: 'PATCH',
    url: '/v1_0/user/photo',
    data
  })
}
